package com.foolishbird.sdk.params.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.foolishbird.sdk.utils.ToolsUtils;
import com.google.gson.annotations.SerializedName;

public class VersionInfo implements Parcelable {

    /**
     * 版本名称
     */
    @SerializedName("version_name")
    private String versionName;

    /**
     * 版本描述
     */
    @SerializedName("version_desc")
    private String versionDesc;

    /**
     * 新版本下载地址
     */
    @SerializedName("version_url")
    private String url;

    /**
     * 是否强制更新
     */
    @SerializedName("version_force_update")
    private int forceUpdate;

    public int getVersionCode() {
        return ToolsUtils.isNumberType(versionName) ? Integer.parseInt(versionName) : 1;
    }

    public String getVersionName() {
        return versionName;
    }

    public void setVersionName(String versionName) {
        this.versionName = versionName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getVersionDesc() {
        return versionDesc;
    }

    public void setVersionDesc(String versionDesc) {
        this.versionDesc = versionDesc;
    }

    public boolean isForceUpdate() {
        return forceUpdate > 0;
    }

    public void setForceUpdate(int forceUpdate) {
        this.forceUpdate = forceUpdate;
    }

    public int getForceUpdate() {
        return forceUpdate;
    }

    public VersionInfo() {
        this.versionName = "0";
        this.url = "";
        this.forceUpdate = 0;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.versionName);
        dest.writeString(this.versionDesc);
        dest.writeString(this.url);
        dest.writeInt(this.forceUpdate);
    }

    protected VersionInfo(Parcel in) {
        this.versionName = in.readString();
        this.versionDesc = in.readString();
        this.url = in.readString();
        this.forceUpdate = in.readInt();
    }

    public static final Creator<VersionInfo> CREATOR = new Creator<VersionInfo>() {
        @Override
        public VersionInfo createFromParcel(Parcel source) {
            return new VersionInfo(source);
        }

        @Override
        public VersionInfo[] newArray(int size) {
            return new VersionInfo[size];
        }
    };
}
